<?php

/**
 * This file is part of the Framework03 PHP framework.
 * @author Walter Tamboer
 * @package Framework03
 */

class FW_GoogleApi_Maps
{
    /**
     * @var string The Google Maps API key.
     */
    private $apiKey = 'ABQIAAAAqxM0ZPhDETLSDMrSeqwzsRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQR4XSjWDd-9cUp8dgtEjcDsGjYDw';
    
    private $latitude = 37.4419;
    
    private $longitude = -122.1419;
    
    /**
     * Sets the Google Maps API key.
     * @param string $apiKey
     * @return FW_GoogleApi_Maps
     */
    public function setApiKey($apiKey)
    {
        $this->apiKey = $apiKey;
        return $this;
    }
    
    /**
     * Gets the Google Maps API key.
     * @return string
     */
    public function getApiKey()
    {
        return $this->apiKey;
    }
    
    /**
     * Creates the JavaScript source of this Google Maps instance.
     * @return string
     */
    public function createSource($includeApi = true, $includeSource = true)
    {
        $source = '';

        if ($includeApi)
        {
            $source .= '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=' . $this->apiKey . '" type="text/javascript"></script>' . "\r\n";
        }

        if ($includeSource)
        {
            $source .= '<script type="text/javascript">
//<![CDATA[

function load()
{
    if (GBrowserIsCompatible())
    {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng('. $this->latitude .', '. $this->longitude .'), 13);
    }
}

//]]>
</script>';
        }
        
        return $source;
    }
}
